package com.qiangesoft.rdp.starter.minio.bucket;

import com.qiangesoft.rdp.starter.minio.bucket.policy.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 桶策略工厂
 *
 * @author qiangesoft
 * @date 2023-08-22
 */
public class BucketPolicyFactory {
    static Map<String, BucketPolicyInterface> operationMap = new HashMap<>();

    static {
        operationMap.put(BucketAccessPolicyEnum.READ.name(), new ReadPolicy());
        operationMap.put(BucketAccessPolicyEnum.WRITE.name(), new WritePolicy());
        operationMap.put(BucketAccessPolicyEnum.READ_WRITE.name(), new ReadWriterPolicy());
    }

    /**
     * 获取桶创建策略
     *
     * @param policy
     * @return
     */
    public static BucketPolicyInterface getBucketPolicyInterface(BucketAccessPolicyEnum policy) {
        if (policy == null) {
            return new DefaultPolicy();
        }
        BucketPolicyInterface object = operationMap.get(policy.name());
        if (object != null) {
            return object;
        }
        return new DefaultPolicy();
    }

}